import 'package:flutter/material.dart';
import 'package:ileddemo/code/ble/protocol/iledcolor/source/SourceManager.dart';

import '../../../generated/l10n.dart';
import '../../ble/protocol/base/SourceInterface.dart';
import '../../ble/protocol/iledcolor/source/ColorSourceInterface.dart';
import '../../ble/protocol/iledcolor/source/SourceSendUtil.dart';

class EditWidget extends StatelessWidget {
  final ColorSourceInterface source;

  const EditWidget({super.key, required this.source});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Container(
        alignment: Alignment.center,
        child: Container(
          margin: EdgeInsets.all(10),
          height: 200,
          decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              _Btn(
                title: S.of(context).str_id_4,
                onTap: () {
                  Navigator.of(context).pop();
                  SourceSendUtil.instance.sendSource(source.castPartitionSourceBean());
                },
              ),
              _Btn(
                title: S.of(context).str_id_37,
                onTap: () {
                  SourceManager.instance.deleteSource(source);
                  Navigator.of(context).pop();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _Btn extends StatelessWidget {
  final String title;
  final GestureTapCallback? onTap;

  const _Btn({super.key, required this.title, this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
        decoration: BoxDecoration(color: Colors.blueGrey, borderRadius: BorderRadius.circular(10)),
        child: Text(title, style: TextStyle(color: Colors.black)),
      ),
    );
  }
}
